package dfbz.expand;

import java.util.Random;
import java.util.Scanner;

public class Test01 {
    public static void main(String[] args) {
        Test01 guess = new Test01();
        guess.guess();
    }
    int x = new Random().nextInt(100) + 1;
    public void guess() {
        guessNumber();
    }

    boolean isTrue = false;
    public void guessNumber () {
        Scanner sc = null;
        sc = new Scanner(System.in);
        while(true) {
            if (!isTrue) {
                System.out.println("请第一位同学输入一个数字: ");
                personGuess(sc);
                isTrue = !isTrue;
            } else{
                System.out.println("请第二位同学输入一个数字: ");
                personGuess(sc);
                isTrue = !isTrue;
            }
        }
    }

    public void personGuess(Scanner sc) {
        int num = sc.nextInt();
        if (x > num) {
            System.out.println("小了");
        } else if (x < num){
            System.out.println("大了");
        } else if(x == num) {
            if (isTrue) {
                System.out.println("恭喜第二位同学猜测成功...,程序结束...");
            } else {
                System.out.println("恭喜第一位同学猜测成功...,程序结束...");
            }
            System.exit(0);
        }
    }
}

